package com.kcht.itsed.mws.aleframework.biz;

import com.kcht.itsed.mws.aleframework.intf.IActiveSpecContainer;
import com.shhic.itsed.mws.deviceintf.RawTagOperationResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;
import java.util.Date;


/**
 * 设备上报的原始反向标签读取结果的处理器，由MDB驱动
 * 从此处将各个标签结果对规则进行拆分，再生成报告云云
 * 和DeviceScheduler模块的IRawTagOperationResultSender接口是好基友
 * 
 * @author 张文硕
 *
 */
@Component
@Slf4j
public class ReservedTagResultProcessorMdb {
	
	@Autowired
	private IActiveSpecContainer activeSpecContainer;

	@JmsListener(destination = "RFID原始标签",containerFactory = "queueFactory")
	public void onMessage(Message msg) {
		try {
			RawTagOperationResult tagRes = (RawTagOperationResult)(((ObjectMessage)msg).getObject());
			process(tagRes);
		} catch (JMSException e) {
			log.error("队列信息获取异常",e);
		}
	}

	private void process(RawTagOperationResult tagRes) {
		log.info("从队列获取的标签--->"+"EPC码:"+tagRes.getTagIdentifier()
				+",IP:"+tagRes.getReaderIp()
				+",天线:"+tagRes.getAntennaNo()
				+",时间:"+new Date(tagRes.getDiscoverTimestamp()));
		activeSpecContainer.dispatchReverseTags(tagRes);
	}

}
